package com.cooper.controllers.admin;

import org.springframework.beans.factory.annotation.Autowired;

import com.cooper.constants.AppConstants;
import com.cooper.controllers.Template;
import com.cooper.core.JsonResult;
import com.cooper.entity.DisplaySelectConfigListDo;
import com.cooper.pagination.PageInfo;
import com.cooper.pagination.PageResult;
import com.cooper.service.admin.DisplayPicConfigService;
import com.cooper.service.seller.DesignerService;
import com.cooper.util.StringUtils;
import com.cooper.vo.CompositeDesignerProjectVo;

import net.paoding.rose.web.Invocation;
import net.paoding.rose.web.annotation.Param;
import net.paoding.rose.web.annotation.rest.Get;
import net.paoding.rose.web.annotation.rest.Post;
import net.paoding.rose.web.portal.Portal;


public class ProjectDesignerSelectController {

	@Autowired 
	DesignerService designerService;
	
	@Autowired
    DisplayPicConfigService displayPicConfigService;
	
	@Template(title="轮播图片配置")
	@Get @Post
	public String content(Invocation inv, Portal portal, PageInfo pageInfo,CompositeDesignerProjectVo queryParamVo) throws Exception{
		pageInfo.setPageSize(5);
		PageResult<CompositeDesignerProjectVo> ret = designerService.findCompositeDesignerProjects(queryParamVo, pageInfo);
		inv.addModel("entryList", ret.getResult());
		inv.addModel(AppConstants.pageInfo, pageInfo);
 		inv.addModel("queryParamVo", queryParamVo);
		return "ProjectDesignerSelect";
	}
	
	@Post("doCheckConfigSelect")
	public Object doCheckConfigSelect(Invocation inv,@Param("outerId") Long outerId,@Param("selectType") String selectType,@Param("status") int status){
		JsonResult json = new JsonResult();
		try{
			if(!(outerId==null)&&StringUtils.isNotEmpty(selectType)){
				DisplaySelectConfigListDo configDo = displayPicConfigService.findDisplaySelectConfig(outerId, selectType);
				if(status==1){
					if(configDo==null){
						configDo = new DisplaySelectConfigListDo();
						configDo.setOuterId(outerId);
						configDo.setSelectType(selectType);
	                }
					displayPicConfigService.addDisplaySelectConfigListDo(configDo);
				}else{
					displayPicConfigService.removeDisplaySelectConfigListDo(configDo.getId());
				}
				json.setSuccess(true);
			}
		}catch(Exception e){
			json.setSuccess(false);
		}
		
		return json;
	}
	
}
